package org.micode.common.codec;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.micode.common.utils.Base64Utils;

import java.io.IOException;

@Slf4j
public class Base64Codec {

    public static <T> T decode(String value, Class<T> clazz) {
        String json = Base64Utils.decode(value);
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.readValue(json, clazz);
        } catch (IOException e) {
            log.error("Decode JSONObject fail!", e);
        }
        return null;
    }

}
